<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="UserID" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="CustNo" prop="custNo">
        <el-input
          v-model="queryParams.custNo"
          placeholder="请输入客户号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="SerialNo" prop="bindSerialNo">
        <el-input
          v-model="queryParams.bindSerialNo"
          placeholder="请输入绑卡流水号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="认证码" prop="authorizationCode">-->
<!--        <el-input-->
<!--          v-model="queryParams.authorizationCode"-->
<!--          placeholder="请输入认证码"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="BankCode" prop="bankCode">
        <el-input
          v-model="queryParams.bankCode"
          placeholder="请输入银行编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="BankName" prop="bankName">-->
<!--        <el-input-->
<!--          v-model="queryParams.bankName"-->
<!--          placeholder="请输入银行名称"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="CardType" prop="cardType">-->
<!--        <el-select v-model="queryParams.cardType" placeholder="请选择银行卡类型" clearable size="small">-->
<!--          <el-option label="请选择字典生成" value=""/>-->
<!--        </el-select>-->
<!--      </el-form-item>-->
      <el-form-item label="CardNumber" prop="cardNumber">
        <el-input
          v-model="queryParams.cardNumber"
          placeholder="请输入银行卡号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="ExpireDate" prop="expireDate">-->
<!--        <el-input-->
<!--          v-model="queryParams.expireDate"-->
<!--          placeholder="请输入有效期"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="Country" prop="country">-->
<!--        <el-input-->
<!--          v-model="queryParams.country"-->
<!--          placeholder="请输入国家简码"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="CountryCode" prop="countryCode">-->
<!--        <el-input-->
<!--          v-model="queryParams.countryCode"-->
<!--          placeholder="请输入国别码"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="Bank&Phone" prop="phoneNumber">-->
<!--        <el-input-->
<!--          v-model="queryParams.phoneNumber"-->
<!--          placeholder="请输入银行卡预留手机号"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="Birthday" prop="birthday">-->
<!--        <el-input-->
<!--          v-model="queryParams.birthday"-->
<!--          placeholder="请输入生日"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="AccountName" prop="accountName">
        <el-input
          v-model="queryParams.accountName"
          placeholder="请输入账户姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="客户编码" prop="customerCode">-->
<!--        <el-input-->
<!--          v-model="queryParams.customerCode"-->
<!--          placeholder="请输入客户编码"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="Email" prop="email">
        <el-input
          v-model="queryParams.email"
          placeholder="请输入邮箱"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="cvv" prop="cvv">-->
<!--        <el-input-->
<!--          v-model="queryParams.cvv"-->
<!--          placeholder="请输入安全码"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="pin" prop="pin">-->
<!--        <el-input-->
<!--          v-model="queryParams.pin"-->
<!--          placeholder="请输入PIN"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="otp" prop="otp">-->
<!--        <el-input-->
<!--          v-model="queryParams.otp"-->
<!--          placeholder="请输入OTP"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="IsDefault" prop="isDefault">
        <el-input
          v-model="queryParams.isDefault"
          placeholder="请输入是否默认卡"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="授权码" prop="accessCode">-->
<!--        <el-input-->
<!--          v-model="queryParams.accessCode"-->
<!--          placeholder="请输入授权码"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="TransAmt" prop="transAmt">-->
<!--        <el-input-->
<!--          v-model="queryParams.transAmt"-->
<!--          placeholder="请输入代扣金额"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="Currency" prop="currency">-->
<!--        <el-input-->
<!--          v-model="queryParams.currency"-->
<!--          placeholder="请输入货币"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="TransactionDate" prop="transactionDate">-->
<!--        <el-input-->
<!--          v-model="queryParams.transactionDate"-->
<!--          placeholder="请输入交易日期"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="State" prop="state">
        <el-select v-model="queryParams.state" placeholder="请选择状态" clearable size="small">
          <el-option
            v-for="dict in stateOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="create date">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="start time"
          end-placeholder="End time"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" style="margin-left: 37px">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['bizsys:cust_bank_card:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['bizsys:cust_bank_card:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['bizsys:cust_bank_card:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['bizsys:cust_bank_card:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="cust_bank_cardList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="ID" align="center" width="100" prop="id"/>
      <el-table-column label="UserID" align="center" width="300" prop="userId"/>
      <el-table-column label="CustNo" align="center" width="200" prop="custNo"/>
      <el-table-column label="SerialNo" align="center" width="240" prop="bindSerialNo"/>
<!--      <el-table-column label="认证码" align="center" width="100" prop="authorizationCode"/>-->
      <el-table-column label="BankCode" align="center" width="100" prop="bankCode"/>
      <el-table-column label="BankName" align="center" width="200" prop="bankName"/>
      <el-table-column label="CardType" align="center" width="150" prop="cardType"/>
      <el-table-column label="CardNumber" align="center" width="120" prop="cardNumber"/>
      <el-table-column label="ExpireDate" align="center" width="100" prop="expireDate"/>
      <el-table-column label="Country" align="center" width="100" prop="country"/>
      <el-table-column label="CountryCode" align="center" width="120" prop="countryCode"/>
      <el-table-column label="PhoneNumber" align="center" width="120" prop="phoneNumber"/>
      <el-table-column label="Birthday" align="center" width="100" prop="birthday"/>
      <el-table-column label="AccountName" align="center" width="270" prop="accountName"/>
      <el-table-column label="CustomerCode" align="center" width="180" prop="customerCode"/>
      <el-table-column label="Email" align="center" width="220" prop="email"/>
<!--      <el-table-column label="安全码" align="center" prop="cvv"/>-->
<!--      <el-table-column label="PIN" align="center" prop="pin"/>-->
<!--      <el-table-column label="OTP" align="center" prop="otp"/>-->
      <el-table-column label="IsDefault" align="center" prop="isDefault"/>
<!--      <el-table-column label="授权码" align="center" prop="accessCode"/>-->
      <el-table-column label="TransAmt" align="center" width="120" prop="transAmt"/>
      <el-table-column label="Currency" align="center" prop="currency"/>
      <el-table-column label="CardStatus" align="center" width="120" prop="cardStatus"/>
      <el-table-column label="TransactionDate" align="center" width="200" prop="transactionDate"/>
      <el-table-column label="State" align="center" prop="state" :formatter="stateFormat"/>
      <el-table-column label="Remark" align="center" width="300" prop="remark"/>
      <el-table-column label="Operation" align="center" width="140" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['bizsys:cust_bank_card:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['bizsys:cust_bank_card:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改客户绑定银行卡对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户ID" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户ID"/>
        </el-form-item>
        <el-form-item label="客户号" prop="custNo">
          <el-input v-model="form.custNo" placeholder="请输入客户号"/>
        </el-form-item>
        <el-form-item label="绑卡流水号" prop="bindSerialNo">
          <el-input v-model="form.bindSerialNo" placeholder="请输入绑卡流水号"/>
        </el-form-item>
        <el-form-item label="认证码" prop="authorizationCode">
          <el-input v-model="form.authorizationCode" placeholder="请输入认证码"/>
        </el-form-item>
        <el-form-item label="银行编码" prop="bankCode">
          <el-input v-model="form.bankCode" placeholder="请输入银行编码"/>
        </el-form-item>
        <el-form-item label="银行名称" prop="bankName">
          <el-input v-model="form.bankName" placeholder="请输入银行名称"/>
        </el-form-item>
        <el-form-item label="银行卡类型" prop="cardType">
          <el-select v-model="form.cardType" placeholder="请选择银行卡类型">
            <el-option label="请选择字典生成" value=""/>
          </el-select>
        </el-form-item>
        <el-form-item label="银行卡号" prop="cardNumber">
          <el-input v-model="form.cardNumber" placeholder="请输入银行卡号"/>
        </el-form-item>
        <el-form-item label="有效期" prop="expireDate">
          <el-input v-model="form.expireDate" placeholder="请输入有效期"/>
        </el-form-item>
        <el-form-item label="国家简码" prop="country">
          <el-input v-model="form.country" placeholder="请输入国家简码"/>
        </el-form-item>
        <el-form-item label="国别码" prop="countryCode">
          <el-input v-model="form.countryCode" placeholder="请输入国别码"/>
        </el-form-item>
        <el-form-item label="银行卡预留手机号" prop="phoneNumber">
          <el-input v-model="form.phoneNumber" placeholder="请输入银行卡预留手机号"/>
        </el-form-item>
        <el-form-item label="生日" prop="birthday">
          <el-input v-model="form.birthday" placeholder="请输入生日"/>
        </el-form-item>
        <el-form-item label="账户姓名" prop="accountName">
          <el-input v-model="form.accountName" placeholder="请输入账户姓名"/>
        </el-form-item>
        <el-form-item label="客户编码" prop="customerCode">
          <el-input v-model="form.customerCode" placeholder="请输入客户编码"/>
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入邮箱"/>
        </el-form-item>
        <el-form-item label="安全码" prop="cvv">
          <el-input v-model="form.cvv" placeholder="请输入安全码"/>
        </el-form-item>
        <el-form-item label="PIN" prop="pin">
          <el-input v-model="form.pin" placeholder="请输入PIN"/>
        </el-form-item>
        <el-form-item label="OTP" prop="otp">
          <el-input v-model="form.otp" placeholder="请输入OTP"/>
        </el-form-item>
        <el-form-item label="是否默认卡" prop="isDefault">
          <el-input v-model="form.isDefault" placeholder="请输入是否默认卡"/>
        </el-form-item>
        <el-form-item label="授权码" prop="accessCode">
          <el-input v-model="form.accessCode" placeholder="请输入授权码"/>
        </el-form-item>
        <el-form-item label="代扣金额" prop="transAmt">
          <el-input v-model="form.transAmt" placeholder="请输入代扣金额"/>
        </el-form-item>
        <el-form-item label="货币" prop="currency">
          <el-input v-model="form.currency" placeholder="请输入货币"/>
        </el-form-item>
        <el-form-item label="交易日期" prop="transactionDate">
          <el-input v-model="form.transactionDate" placeholder="请输入交易日期"/>
        </el-form-item>
        <el-form-item label="状态" prop="state">
          <el-select v-model="form.state" placeholder="请选择状态">
            <el-option
              v-for="dict in stateOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listCust_bank_card,
  getCust_bank_card,
  delCust_bank_card,
  addCust_bank_card,
  updateCust_bank_card,
  exportCust_bank_card
} from "@/api/bizsys/cust_bank_card";

export default {
  name: "Cust_bank_card",
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 客户绑定银行卡表格数据
      cust_bank_cardList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 状态字典
      stateOptions: [],
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        custNo: null,
        bindSerialNo: null,
        authorizationCode: null,
        bankCode: null,
        bankName: null,
        cardType: null,
        cardNumber: null,
        expireDate: null,
        country: null,
        countryCode: null,
        phoneNumber: null,
        birthday: null,
        accountName: null,
        customerCode: null,
        email: null,
        cvv: null,
        pin: null,
        otp: null,
        isDefault: null,
        accessCode: null,
        transAmt: null,
        currency: null,
        transactionDate: null,
        state: null,
        cardStatus:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userId: [
          {required: true, message: "用户ID不能为空", trigger: "blur"}
        ],
        bindSerialNo: [
          {required: true, message: "绑卡流水号不能为空", trigger: "blur"}
        ],
        isDefault: [
          {required: true, message: "是否默认卡不能为空", trigger: "blur"}
        ],
        createTime: [
          {required: true, message: "创建时间不能为空", trigger: "blur"}
        ],
        updateTime: [
          {required: true, message: "更新时间不能为空", trigger: "blur"}
        ]
      }
    };
  },
  created() {
    // this.getList();
    this.getDicts("state").then(response => {
      this.stateOptions = response.data;
    });
  },
  methods: {
    /** 查询客户绑定银行卡列表 */
    getList() {
      this.loading = true;
      listCust_bank_card(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.cust_bank_cardList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 状态字典翻译
    stateFormat(row, column) {
      return this.selectDictLabel(this.stateOptions, row.state);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        custNo: null,
        bindSerialNo: null,
        authorizationCode: null,
        bankCode: null,
        bankName: null,
        cardType: null,
        cardNumber: null,
        expireDate: null,
        country: null,
        countryCode: null,
        phoneNumber: null,
        birthday: null,
        accountName: null,
        customerCode: null,
        email: null,
        cvv: null,
        pin: null,
        otp: null,
        isDefault: null,
        accessCode: null,
        transAmt: null,
        currency: null,
        transactionDate: null,
        state: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        dateRange: []
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
      this.dateRange = [];
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加客户绑定银行卡";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCust_bank_card(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改客户绑定银行卡";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCust_bank_card(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCust_bank_card(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除客户绑定银行卡编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delCust_bank_card(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有客户绑定银行卡数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return exportCust_bank_card(queryParams);
      }).then(response => {
        this.download(response.msg);
      })
    }
  }
};
</script>
